use std::str::FromStr;

pub fn convert_base(num_str: &str, to_base: u32) -> String {
    let mut num_base_iter = num_str.split(['(', ')']);
    let (num, base) = match (num_base_iter.next(), num_base_iter.next()) {
        (Some(num), Some(base)) => (num, base),
        _ => panic!("Invalid input"),
    };
    let mut num = u32::from_str_radix(num, u32::from_str(base).unwrap()).unwrap();

    let mut ret = Vec::new();
    while num > 0 {
        ret.push(std::char::from_digit(num % to_base, to_base).expect("Invalid base"));
        num /= to_base;
    }
    ret.iter().rev().collect()
}
